package logic

import (
	"context"
	"fmt"
	"house_srv/model/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowHouseLogic {
	return &ShowHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowHouseLogic) ShowHouse(in *house.ShowHouseRequest) (*house.ShowHouseResponse, error) {
	// todo: add your logic here and delete this line
	h := mysql.House{}
	err := h.GetList(in.Id)
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}

	return &house.ShowHouseResponse{
		HouseTitle:   h.HouseTitle,
		HouseAddress: h.HouseAddress,
		HouseIntro:   h.HouseIntro,
		HousePrice:   float32(h.HousePrice),
		Id:           int64(h.ID),
	}, nil
}
